// File Name: oled_logic.c
// Author: kukukukuku~
// Date: 2024-07-04

#include "./User/ADC/inc/adc_ctrl.h"
#include "./User/Key/inc/key_ctrl.h"
#include "./User/LED/inc/led_logic.h"
#include "./User/OLED/inc/oled_font.h"
#include "./User/OLED/inc/oled_logic.h"
#include "./User/Step_Motor/inc/step_motor_logic.h"
#include "./User/WS2812B/inc/ws2812b_ctrl.h"
#include "stdio.h"
#include "string.h"

static uint16_t temp = 0xFFFF;  //临时变量
static uint8_t str[32]; //临时字符串

/**
 * @brief   OLED设置坐标
 * @param   x:  横坐标
 * @param   y:  纵坐标
 * @retval  None
 * @note    None
*/
void oled_set_position(uint8_t x, uint8_t y)
{
    //限制可显示范围
    if(x > OLED_COLUMN_MAX - 8)
    {
        x = OLED_COLUMN_MAX - 8;
    }
    if(y > OLED_PAGE_MAX - 1)
    {
        y = OLED_PAGE_MAX - 1;
    }
    
    oled_iic_send_data(0xB0 + y, OLED_SEND_CMD);
    oled_iic_send_data((x & 0xF0) >> 4 | 0x10, OLED_SEND_CMD);
    oled_iic_send_data(x & 0x0F, OLED_SEND_CMD);
}


/**
 * @brief   OLED开启显示
 * @param   None
 * @retval  None
 * @note    None
*/
void oled_display_on(void)
{
    oled_iic_send_data(0x8D, OLED_SEND_CMD);
    oled_iic_send_data(0x14, OLED_SEND_CMD);
    oled_iic_send_data(0xAF, OLED_SEND_CMD);
}


/**
 * @brief   OLED关闭显示
 * @param   None
 * @retval  None
 * @note    None
*/
void oled_display_off(void)
{
    oled_iic_send_data(0x8D, OLED_SEND_CMD);
    oled_iic_send_data(0x10, OLED_SEND_CMD);
    oled_iic_send_data(0xAE, OLED_SEND_CMD);
}


/**
 * @brief   OLED清除屏幕
 * @param   None
 * @retval  None
 * @note    None
*/
void oled_clear(void)
{
    for(uint8_t i = 0; i < OLED_PAGE_MAX; i++)
    {
        oled_iic_send_data(0xB0+i, OLED_SEND_CMD);
        oled_iic_send_data(0x00, OLED_SEND_CMD);
        oled_iic_send_data(0x10, OLED_SEND_CMD);
        for(uint8_t j = 0; j < OLED_COLUMN_MAX; j++)
        {
            oled_iic_send_data(0x00, OLED_SEND_DATA);
        }
    }
}


/**
 * @brief   OLED显示一个8x16字符
 * @param   x:          横坐标
 * @param   y:          纵坐标
 * @param   ch:         要显示的字符
 * @param   mode:       显示模式
 * 0:   正相
 * 1:   反向
 * @retval  None
 * @note    None
*/
void oled_show_char_8x16(uint8_t x, uint8_t y, uint8_t ch, uint8_t mode)
{
    if(ch > 127)
    {
        ch = 127;
    }
    
    //限制坐标
    if(x > OLED_COLUMN_MAX - 8)
    {
        x = 0;
        y += 2;
    }
    if(y > OLED_PAGE_MAX - 2)
    {
        y = 0;
    }
    
    //一个字符占两页
    for(uint8_t i = 0; i < 2; i++)
    {
        oled_set_position(x, y + i);
        
        //一个字符在每页占8列
        for(uint8_t j = 0; j < 8; j++)
        {
            mode ?\
            oled_iic_send_data(~oledFont8x16[ch * 16 + (8 * i) + j], OLED_SEND_DATA) :\
            oled_iic_send_data(oledFont8x16[ch * 16 + (8 * i) + j], OLED_SEND_DATA);
        }
    }
}


/**
 * @brief   OLED显示8x16字符串
 * @param   x:          横坐标
 * @param   y:          纵坐标
 * @param   str:        要显示的字符串
 * @param   mode:       显示模式
 * 0:   正相
 * 1:   反向
 * @retval  None
 * @note    None
*/
void oled_show_str_8x16(uint8_t x, uint8_t y, const uint8_t * const str, uint8_t mode)
{
    uint32_t i = 0;
    
    if(str == NULL)
    {
        return;
    }
    
    while(str[i])
    {
        //限制坐标
        if(x > OLED_COLUMN_MAX - 8)
        {
            x = 0;
            y += 2;
        }
        if(y > OLED_PAGE_MAX - 2)
        {
            y = 0;
        }
        
        oled_show_char_8x16(x, y, str[i++], mode);
        
        x += 8;
    }
}


/**
 * @brief   OLED显示16x16中文
 * @param   x:              横坐标
 * @param   y:              纵坐标
 * @param   oledFontSource: 字库源
 * @param   oledFontNum:    中文字符个数
 * @param   mode:       显示模式
 * 0:   正相
 * 1:   反向
 * @retval  None
 * @note    None
*/
void oled_show_chinese_16x16(uint8_t x, uint8_t y, const uint8_t *oledFontSource, uint8_t oledFontNum, uint8_t mode)
{
    for(uint8_t i = 0; i < oledFontNum; i++)
    {
        //限制坐标
        if(x > OLED_COLUMN_MAX - 16)
        {
            x = 0;
            y += 2;
        }
        if(y > OLED_PAGE_MAX - 2)
        {
            y = 0;
        }
        
        //一个字符占两页
        for(uint8_t j = 0; j < 2; j++)
        {
            oled_set_position(x, y + j);
            
            //一个字符在每页占16列
            for(uint8_t k = 0; k < 16; k++)
            {
                mode ?\
                oled_iic_send_data(~oledFontSource[32 * i + (16 * j) + k], OLED_SEND_DATA) :\
                oled_iic_send_data(oledFontSource[32 * i + (16 * j) + k], OLED_SEND_DATA);
            }
        }
        
        x += 16;
    }
}


/**
 * @brief   OLED显示主界面
 * @param   mainId: 界面编号
 * @retval  None
 * @note    None
*/
void oled_dis_main(uint8_t mainId)
{
    static uint8_t str[32];
    
    memset(str, 0, sizeof(str));
    
    switch(mainId)
    {
        case 0:
            sprintf((char *)str, "Temp: %2u.%2u", (uint32_t)temperature, (uint32_t)(temperature * 100) % 100);
            break;
        case 1:
            sprintf((char *)str, "Key click beep: %u", keyClickBeep);
            break;
        case 2:
            sprintf((char *)str, "Key long beep: %u", keyLongBeep);
            break;
        case 3:
            led1.mode == LED_MODE_BREATH ? sprintf((char *)str, "LED1 mode: breath") : sprintf((char *)str, "LED1 mode: blink");
            break;
        case 4:
            sprintf((char *)str, "LED1 breath step: %u", led1.breathStep);
            break;
        case 5:
            sprintf((char *)str, "LED1 blink freq: %u", led1.blinkNum);
            break;
        case 6:
            led2.mode == LED_MODE_BREATH ? sprintf((char *)str, "LED2 mode: breath") : sprintf((char *)str, "LED2 mode: blink");
            break;
        case 7:
            sprintf((char *)str, "LED2 breath step: %u", led2.breathStep);
            break;
        case 8:
            sprintf((char *)str, "LED2 blink freq: %u", led2.blinkNum);
            break;
        case 9:
            oledDir ? sprintf((char *)str, "OLED dir: reverse") : sprintf((char *)str, "OLED dir: normal");
            break;
        case 10:
            if(oledLightLevel == 0)
                sprintf((char *)str, "OLED light: high");
            else if(oledLightLevel == 1)
                sprintf((char *)str, "OLED light: mid");
            else if(oledLightLevel == 2)
                sprintf((char *)str, "OLED light: low");
            break;
        case 11:
            if(stepMotorState == STEP_MOTOR_STOP)
                sprintf((char *)str, "Step motor state: stop");
            else if(stepMotorState == STEP_MOTOR_CW)
                sprintf((char *)str, "Step motor state: cw");
            else if(stepMotorState == STEP_MOTOR_CCW)
                sprintf((char *)str, "Step motor state: ccw");
            break;
        case 12:
            if(stepMotorMode == FULL_STEP)
                sprintf((char *)str, "Step motor mode: full");
            else if(stepMotorMode == HALF_STEP)
                sprintf((char *)str, "Step motor mode: half");
            else if(stepMotorMode == QUARTER_STEP)
                sprintf((char *)str, "Step motor mode: quarter");
            else if(stepMotorMode == EIGHTH_STEP)
                sprintf((char *)str, "Step motor mode: eighth");
            else if(stepMotorMode == SIXTEENTH_STEP)
                sprintf((char *)str, "Step motor mode: sixteenth");
            break;
        case 13:
            if(stepMotorSpd == 0)
                sprintf((char *)str, "Step motor speed: ultra-fast");
            else if(stepMotorSpd == 1)
                sprintf((char *)str, "Step motor speed: fast");
            else if(stepMotorSpd == 2)
                sprintf((char *)str, "Step motor speed: normal");
            else if(stepMotorSpd == 3)
                sprintf((char *)str, "Step motor speed: low");
            else if(stepMotorSpd == 4)
                sprintf((char *)str, "Step motor speed: ultra-low");
            break;
        default:
            break;
    }
    
    oled_show_str_8x16(0, 0, str, 0);
//    memset(str, 0, sizeof(str));
//    
//    if(keyLockFlag)
//    {
//        sprintf((char *)str, "%3u^", mainId + 1);
//        oled_show_str_8x16(OLED_COLUMN_MAX - 4 * 8, OLED_PAGE_MAX - 2, str, 0);
//    }
//    else
//    {
//        sprintf((char *)str, "%3u", mainId + 1);
//        oled_show_str_8x16(OLED_COLUMN_MAX - 3 * 8, OLED_PAGE_MAX - 2, str, 0);
//    }
}


/**
 * @brief   OLED显示菜单
 * @param   oledMenu:   菜单对象
 * @retval  选中的菜单
 * @note    None
*/
uint8_t oled_dis_menu(pOledMenu oledMenu)
{
    uint8_t ret = 0xFF;
    
    static uint8_t indexStr[10];
    
    oledItemUpDnEnaFlag = 1;
    
    //选项上移
    if(oledItemUpFlag)
    {
        if(oledMenu->itemIndex > 0)
        {
            --oledMenu->itemIndex;
        }
        
        if(oledMenu->oledRowIndex > 0)
        {
            --oledMenu->oledRowIndex;
        }
        
        oledItemUpFlag = 0;
    }
    
    //选项下移
    if(oledItemDnFlag)
    {
        if(oledMenu->itemIndex < oledMenu->itemNum-1)
        {
            ++oledMenu->itemIndex;
        }
        
        if(oledMenu->oledRowIndex < 1 && oledMenu->oledRowIndex < oledMenu->itemIndex)
        {
            ++oledMenu->oledRowIndex;
        }
        
        oledItemDnFlag = 0;
    }
    
    //选项确认
    if(oledItemSelectFlag)
    {
        if(oledMenu->itemIndex == oledMenu->itemNum-1)
        {
            if(oledMenuLevel > 0)
            {
                --oledMenuLevel;
            }
            else
            {
                oledDisModeFlag = 0;
            }
        }
        else
        {
            if(oledMenu->item[oledMenu->itemIndex].nextLevelFlag)
            {
                ++oledMenuLevel;
            }
            else
            {
                oledMenuLevel = 0;
            }
        }
        
        ret = oledMenu->itemIndex;
        oledMenu->itemIndex = oledMenu->oledRowIndex = 0;
        oledMenu->itemIndexLast = oledMenu->oledRowIndexLast = -1;
        
        oledItemUpDnEnaFlag = 0;
        oledItemSelectFlag = 0;
        oled_clear();
        
        return ret;
    }
    
    if(oledMenu->itemIndexLast != oledMenu->itemIndex || oledMenu->oledRowIndexLast != oledMenu->oledRowIndex)
    {
        oled_clear();
        oledMenu->itemIndexLast = oledMenu->itemIndex;
        oledMenu->oledRowIndexLast = oledMenu->oledRowIndex;
    }
    
    oled_show_str_8x16(0, 0, oledMenu->item[oledMenu->itemIndex-oledMenu->oledRowIndex].itemName, oledMenu->oledRowIndex == 0 ? 1 : 0);
    if(oledMenu->itemNum > 1)
    {
        oled_show_str_8x16(0, 2, oledMenu->item[oledMenu->itemIndex-oledMenu->oledRowIndex+1].itemName, oledMenu->oledRowIndex == 1 ? 1 : 0);
    }
//    if(oledMenu->itemNum > 3)
//    {
//        oled_show_str_8x16(0, 2, oledMenu->item[oledMenu->itemIndex-oledMenu->oledRowIndex+1].itemName, oledMenu->oledRowIndex == 1 ? 1 : 0);
//        oled_show_str_8x16(0, 4, oledMenu->item[oledMenu->itemIndex-oledMenu->oledRowIndex+2].itemName, oledMenu->oledRowIndex == 2 ? 1 : 0);
//        oled_show_str_8x16(0, 6, oledMenu->item[oledMenu->itemIndex-oledMenu->oledRowIndex+3].itemName, oledMenu->oledRowIndex == 3 ? 1 : 0);
//    }
//    else if(oledMenu->itemNum > 2)
//    {
//        oled_show_str_8x16(0, 2, oledMenu->item[oledMenu->itemIndex-oledMenu->oledRowIndex+1].itemName, oledMenu->oledRowIndex == 1 ? 1 : 0);
//        oled_show_str_8x16(0, 4, oledMenu->item[oledMenu->itemIndex-oledMenu->oledRowIndex+2].itemName, oledMenu->oledRowIndex == 2 ? 1 : 0);
//    }
//    else if(oledMenu->itemNum > 1)
//    {
//        oled_show_str_8x16(0, 2, oledMenu->item[oledMenu->itemIndex-oledMenu->oledRowIndex+1].itemName, oledMenu->oledRowIndex == 1 ? 1 : 0);
//    }
    
    memset(indexStr, 0, sizeof(indexStr));
    sprintf((char *)indexStr, "%2u", oledMenu->itemIndex + 1);
    oled_show_str_8x16(OLED_COLUMN_MAX - 2 * 8, OLED_PAGE_MAX - 2, indexStr, 0);
    
    return ret;
}


/**
 * @brief   OLED设置数值
 * @param   currentVal: 当前值
 * @param   minVal:     最小值
 * @param   maxVal:     最大值
 * @retval  要设置的值
 * @note    None
*/
uint16_t oled_set_val(const uint8_t * const title, const uint16_t currentVal, const uint16_t minVal, const uint16_t maxVal)
{
    uint16_t ret = 0;
    
    if(title == NULL || minVal >= maxVal)
    {
        return 0xFFFF;
    }
    
    if(temp == 0xFFFF)
    {
        temp = currentVal;
    }
    
    oledValSetEnaFlag = 1;
    
    //数值减小
    if(oledValSetSubFlag || key[KEY_LEFT_INDEX].state == KEY_STATE_CLICK_LONG)
    {
        if(temp > minVal)
        {
            --temp;
            
            if(temp == 9 || temp == 99 || temp == 999 || temp == 9999)
            {
                oled_clear();
            }
        }
        
        oledValSetSubFlag = 0;
    }
    
    //数值增大
    if(oledValSetPlusFlag || key[KEY_RIGHT_INDEX].state == KEY_STATE_CLICK_LONG)
    {
        if(temp < maxVal)
        {
            ++temp;
            
            if(temp == 10 || temp == 100 || temp == 1000 || temp == 10000)
            {
                oled_clear();
            }
        }
        
        oledValSetPlusFlag = 0;
    }
    
    //数值确定
    if(oledItemSelectFlag)
    {
        oledItemSelectFlag == 1 ? (ret = temp) : (ret = 0xFFFF);
        temp = 0xFFFF;
        
        oledValSetEnaFlag = 0;
        oledMenuLevel = 0;
        oledItemSelectFlag = 0;
        
        oled_clear();
        
        return ret;
    }
    
    memset(str, 0, sizeof(str));
    sprintf((char *)str, "%u", temp);
    
    oled_show_str_8x16(0, 0, title, 0);
    
    oled_show_char_8x16(0, OLED_PAGE_MAX - 2, '<', 0);
    oled_show_char_8x16(OLED_COLUMN_MAX - 8, OLED_PAGE_MAX - 2, '>', 0);
    
    if(temp < 10)
        oled_show_str_8x16((OLED_COLUMN_MAX - 1 * 8) / 2, OLED_PAGE_MAX - 2, str, 1);
    else if(temp < 100)
        oled_show_str_8x16((OLED_COLUMN_MAX - 2 * 8) / 2, OLED_PAGE_MAX - 2, str, 1);
    else if(temp < 1000)
        oled_show_str_8x16((OLED_COLUMN_MAX - 3 * 8) / 2, OLED_PAGE_MAX - 2, str, 1);
    else if(temp < 10000)
        oled_show_str_8x16((OLED_COLUMN_MAX - 4 * 8) / 2, OLED_PAGE_MAX - 2, str, 1);
    else
        oled_show_str_8x16((OLED_COLUMN_MAX - 5 * 8) / 2, OLED_PAGE_MAX - 2, str, 1);
    
    return 0xFFFF;
}


/**
 * @brief   OLED Key三级菜单显示
 * @param   None
 * @retval  None
 * @note    None
*/
void oled_menu_level3_key(void)
{
    //匹配二级菜单编号
    switch(oledSelectLevel2)
    {
        //按键短按蜂鸣时间
        case OLED_LEVEL2_KEY_CLICK_BEEP_INDEX:
            {
                uint16_t temp = oled_set_val(oledMenuKey.item[OLED_LEVEL2_KEY_CLICK_BEEP_INDEX].itemName,\
                keyClickBeep, KEY_CLICK_BEEP_MIN, KEY_CLICK_BEEP_MAX);
                
                if(temp == 0xFFFF)
                    break;
                
                keyClickBeep = temp;
            }
            break;
        //按键长按蜂鸣时间
        case OLED_LEVEL2_KEY_LONG_BEEP_INDEX:
            {
                uint16_t temp = oled_set_val(oledMenuKey.item[OLED_LEVEL2_KEY_LONG_BEEP_INDEX].itemName,\
                keyLongBeep, KEY_LONG_BEEP_MIN, KEY_LONG_BEEP_MAX);
                
                if(temp == 0xFFFF)
                    break;
                
                keyLongBeep = temp;
            }
            break;
        default:
            break;
    }
}


/**
 * @brief   OLED LED三级菜单显示
 * @param   None
 * @retval  None
 * @note    None
*/
void oled_menu_level3_led(void)
{
    //匹配二级菜单编号
    switch(oledSelectLevel2)
    {
        //LED1 & LED2
        case OLED_LEVEL2_LED1_INDEX:
        case OLED_LEVEL2_LED2_INDEX:
            oledSelectLevel3 = oled_dis_menu(&oledMenuLedOption);
            break;
        default:
            break;
    }
}


/**
 * @brief   OLED OLED三级菜单显示
 * @param   None
 * @retval  None
 * @note    None
*/
void oled_menu_level3_oled(void)
{
    //匹配二级菜单编号
    switch(oledSelectLevel2)
    {
        //OLED dir
        case OLED_LEVEL2_OLED_DIR_INDEX:
            oledSelectLevel3 = oled_dis_menu(&oledMenuOledDir);
            
            //匹配三级菜单编号
            switch(oledSelectLevel3)
            {
                //OLED正常模式
                case OLED_LEVEL3_OLED_DIR_NORMAL:
                    oled_iic_send_data(0xC8, OLED_SEND_CMD);
                    oled_iic_send_data(0xA1, OLED_SEND_CMD);
                    oledDir = 0;
                    break;
                //OLED反转模式
                case OLED_LEVEL3_OLED_DIR_REVERSE:
                    oled_iic_send_data(0xC0, OLED_SEND_CMD);
                    oled_iic_send_data(0xA0, OLED_SEND_CMD);
                    oledDir = 1;
                    break;
                default:
                    break;
            }
            break;
        //OLED light
        case OLED_LEVEL2_OLED_LIGHT_INDEX:
            oledSelectLevel3 = oled_dis_menu(&oledMenuOledLight);
            
            //匹配三级菜单编号
            switch(oledSelectLevel3)
            {
                //OLED高亮度
                case OLED_LEVEL3_OLED_LIGHT_HIGH:
                    oled_iic_send_data(0x81, OLED_SEND_CMD);
                    oled_iic_send_data(0xFA, OLED_SEND_CMD);
                    oledLightLevel = 0;
                    break;
                //OLED中亮度
                case OLED_LEVEL3_OLED_LIGHT_MID:
                    oled_iic_send_data(0x81, OLED_SEND_CMD);
                    oled_iic_send_data(0x96, OLED_SEND_CMD);
                    oledLightLevel = 1;
                    break;
                //OLED低亮度
                case OLED_LEVEL3_OLED_LIGHT_LOW:
                    oled_iic_send_data(0x81, OLED_SEND_CMD);
                    oled_iic_send_data(0x32, OLED_SEND_CMD);
                    oledLightLevel = 2;
                    break;
                default:
                    break;
            }
            break;
        default:
            break;
    }
}


/**
 * @brief   OLED Step_Motor三级菜单显示
 * @param   None
 * @retval  None
 * @note    None
*/
void oled_menu_level3_step_motor(void)
{
    //匹配二级菜单编号
    switch(oledSelectLevel2)
    {
        //Step motor mode
        case OLED_LEVEL2_STEP_MOTOR_MODE_INDEX:
            oledSelectLevel3 = oled_dis_menu(&oledMenuStepMotorMode);
            
            //匹配三级菜单编号
            switch(oledSelectLevel3)
            {
                //200
                case OLED_LEVEL3_STEP_MOTOR_MODE_FULL_INDEX:
                    step_motor_set_mode(FULL_STEP);
                    break;
                //400
                case OLED_LEVEL3_STEP_MOTOR_MODE_HALF_INDEX:
                    step_motor_set_mode(HALF_STEP);
                    break;
                //800
                case OLED_LEVEL3_STEP_MOTOR_MODE_QUARTER_INDEX:
                    step_motor_set_mode(QUARTER_STEP);
                    break;
                //1600
                case OLED_LEVEL3_STEP_MOTOR_MODE_EIGHTH_INDEX:
                    step_motor_set_mode(EIGHTH_STEP);
                    break;
                //3200
                case OLED_LEVEL3_STEP_MOTOR_MODE_SIXTEENTH_INDEX:
                    step_motor_set_mode(SIXTEENTH_STEP);
                    break;
                default:
                    break;
            }
            break;
        //Step motor speed
        case OLED_LEVEL2_STEP_MOTOR_SPD_INDEX:
            oledSelectLevel3 = oled_dis_menu(&oledMenuStepMotorSpd);
            
            if(oledSelectLevel3 == 0xFF)
                break;
            
            step_motor_set_rotate_speed(oledSelectLevel3);
            
            break;
        default:
            break;
    }
}


/**
 * @brief   OLED WS2812B三级菜单显示
 * @param   None
 * @retval  None
 * @note    None
*/
void oled_menu_level3_ws2812b(void)
{
    //匹配二级菜单编号
    switch(oledSelectLevel2)
    {
        //Cw & Ccw Color
        case OLED_LEVEL2_WS2812B_CW_COLOR_INDEX:
        case OLED_LEVEL2_WS2812B_CCW_COLOR_INDEX:
            oledSelectLevel3 = oled_dis_menu(&oledMenuWs2812bMode);
            
            //匹配三级菜单编号
            switch(oledSelectLevel3)
            {
                //随机值
                case OLED_LEVEL3_WS2812B_MODE_RANDOM_INDEX:
                    {
                        oledSelectLevel2 == OLED_LEVEL2_WS2812B_CW_COLOR_INDEX ? (ws2812bCwMode = 0) : (ws2812bCcwMode = 0);
                    }
                    break;
                default:
                    break;
            }
            break;
        default:
            break;
    }
}


/**
 * @brief   OLED LED四级菜单显示
 * @param   None
 * @retval  None
 * @note    None
*/
void oled_menu_level4_led(void)
{
    //匹配二级菜单编号
    switch(oledSelectLevel2)
    {
        //LED1 & LED2
        case OLED_LEVEL2_LED1_INDEX:
        case OLED_LEVEL2_LED2_INDEX:
            {
                //匹配三级菜单编号
                switch(oledSelectLevel3)
                {
                    //LED模式
                    case OLED_LEVEL3_LED_MODE_INDEX:
                        {
                            oledSelectLevel4 = oled_dis_menu(&oledMenuLedMode);
                            
                            //匹配四级菜单编号
                            switch(oledSelectLevel4)
                            {
                                //LED呼吸灯模式
                                case OLED_LEVEL4_LED_MODE_BREATH_INDEX:
                                    {
                                        if(oledSelectLevel2 == OLED_LEVEL2_LED1_INDEX)
                                        {
                                            led_set_mode(&led1, LED_MODE_BREATH);
                                        }
                                        else if(oledSelectLevel2 == OLED_LEVEL2_LED2_INDEX)
                                        {
                                            led_set_mode(&led2, LED_MODE_BREATH);
                                        }
                                    }
                                    break;
                                //LED闪烁模式
                                case OLED_LEVEL4_LED_MODE_BLINK_INDEX:
                                    {
                                        if(oledSelectLevel2 == OLED_LEVEL2_LED1_INDEX)
                                        {
                                            led_set_mode(&led1, LED_MODE_BLINK);
                                        }
                                        else if(oledSelectLevel2 == OLED_LEVEL2_LED2_INDEX)
                                        {
                                            led_set_mode(&led2, LED_MODE_BLINK);
                                        }
                                    }
                                    break;
                                default:
                                    break;
                            }
                        }
                        break;
                    //LED闪烁频率
                    case OLED_LEVEL3_LED_BLINK_FREQ_INDEX:
                        {
                            if(oledSelectLevel2 == OLED_LEVEL2_LED1_INDEX)
                            {
                                uint16_t temp = oled_set_val(oledMenuLedOption.item[OLED_LEVEL3_LED_BLINK_FREQ_INDEX].itemName,\
                                led1.blinkNum, LED_BLINK_TIME_MIN, LED_BLINK_TIME_MAX);
                                
                                if(temp == 0xFFFF)
                                    break;
                                
                                led_set_blink_time(&led1, temp);
                            }
                            else if(oledSelectLevel2 == OLED_LEVEL2_LED2_INDEX)
                            {
                                uint16_t temp = oled_set_val(oledMenuLedOption.item[OLED_LEVEL3_LED_BLINK_FREQ_INDEX].itemName,\
                                led2.blinkNum, LED_BLINK_TIME_MIN, LED_BLINK_TIME_MAX);
                                
                                if(temp == 0xFFFF)
                                    break;
                                
                                led_set_blink_time(&led2, temp);
                            }
                        }
                        break;
                    //LED呼吸步进
                    case OLED_LEVEL3_LED_BREATH_STEP_INDEX:
                        {
                            if(oledSelectLevel2 == OLED_LEVEL2_LED1_INDEX)
                            {
                                uint16_t temp = oled_set_val(oledMenuLedOption.item[OLED_LEVEL3_LED_BREATH_STEP_INDEX].itemName,\
                                led1.breathStep, LED_BREATH_STEP_MIN, LED_BREATH_STEP_MAX);
                                
                                if(temp == 0xFFFF)
                                    break;
                                
                                led_set_breath_step(&led1, temp);
                            }
                            else if(oledSelectLevel2 == OLED_LEVEL2_LED2_INDEX)
                            {
                                uint16_t temp = oled_set_val(oledMenuLedOption.item[OLED_LEVEL3_LED_BREATH_STEP_INDEX].itemName,\
                                led2.breathStep, LED_BREATH_STEP_MIN, LED_BREATH_STEP_MAX);
                                
                                if(temp == 0xFFFF)
                                    break;
                                
                                led_set_breath_step(&led2, temp);
                            }
                        }
                        break;
                    default:
                        break;
                }
            }
            break;
        default:
            break;
    }
}


/**
 * @brief   OLED WS2812B四级菜单显示
 * @param   None
 * @retval  None
 * @note    None
*/
void oled_menu_level4_ws2812b(void)
{
    //匹配二级菜单编号
    switch(oledSelectLevel2)
    {
        //Cw & Ccw Color
        case OLED_LEVEL2_WS2812B_CW_COLOR_INDEX:
        case OLED_LEVEL2_WS2812B_CCW_COLOR_INDEX:
            {
                //匹配三级菜单编号
                switch(oledSelectLevel3)
                {
                    //固定值
                    case OLED_LEVEL3_WS2812B_MODE_FIXED_INDEX:
                        oledSelectLevel4 = oled_dis_menu(&oledMenuWs2812bFixed);
                        break;
                    default:
                        break;
                }
            }
            break;
        default:
            break;
    }
}


/**
 * @brief   OLED WS2812B五级菜单显示
 * @param   None
 * @retval  None
 * @note    None
*/
void oled_menu_level5_ws2812b(void)
{
    //匹配二级菜单编号
    switch(oledSelectLevel2)
    {
        //Cw & Ccw Color
        case OLED_LEVEL2_WS2812B_CW_COLOR_INDEX:
        case OLED_LEVEL2_WS2812B_CCW_COLOR_INDEX:
            {
                //匹配三级菜单编号
                switch(oledSelectLevel3)
                {
                    //固定值
                    case OLED_LEVEL3_WS2812B_MODE_FIXED_INDEX:
                        {
                            //匹配四级菜单编号
                            switch(oledSelectLevel4)
                            {
                                //设置红色
                                case OLED_LEVEL4_WS2812B_RED:
                                    if(oledSelectLevel2 == OLED_LEVEL2_WS2812B_CW_COLOR_INDEX)
                                    {
                                        uint16_t temp = oled_set_val(oledMenuWs2812bFixed.item[OLED_LEVEL4_WS2812B_RED].itemName,\
                                        ws2812bCwRed, WS2812B_RGB_VAL_MIN, WS2812B_RGB_VAL_MAX);
                                        
                                        if(temp == 0xFFFF)
                                            break;
                                        
                                        ws2812bCwRed = temp;
                                        ws2812bCwMode = 1;
                                    }
                                    else if(oledSelectLevel2 == OLED_LEVEL2_WS2812B_CCW_COLOR_INDEX)
                                    {
                                        uint16_t temp = oled_set_val(oledMenuWs2812bFixed.item[OLED_LEVEL4_WS2812B_RED].itemName,\
                                        ws2812bCcwRed, WS2812B_RGB_VAL_MIN, WS2812B_RGB_VAL_MAX);
                                        
                                        if(temp == 0xFFFF)
                                            break;
                                        
                                        ws2812bCcwRed = temp;
                                        ws2812bCcwMode = 1;
                                    }
                                    break;
                                //设置绿色
                                case OLED_LEVEL4_WS2812B_GREEN:
                                    if(oledSelectLevel2 == OLED_LEVEL2_WS2812B_CW_COLOR_INDEX)
                                    {
                                        uint16_t temp = oled_set_val(oledMenuWs2812bFixed.item[OLED_LEVEL4_WS2812B_GREEN].itemName,\
                                        ws2812bCwGreen, WS2812B_RGB_VAL_MIN, WS2812B_RGB_VAL_MAX);
                                        
                                        if(temp == 0xFFFF)
                                            break;
                                        
                                        ws2812bCwGreen = temp;
                                        ws2812bCwMode = 1;
                                    }
                                    else if(oledSelectLevel2 == OLED_LEVEL2_WS2812B_CCW_COLOR_INDEX)
                                    {
                                        uint16_t temp = oled_set_val(oledMenuWs2812bFixed.item[OLED_LEVEL4_WS2812B_GREEN].itemName,\
                                        ws2812bCcwGreen, WS2812B_RGB_VAL_MIN, WS2812B_RGB_VAL_MAX);
                                        
                                        if(temp == 0xFFFF)
                                            break;
                                        
                                        ws2812bCcwGreen = temp;
                                        ws2812bCcwMode = 1;
                                    }
                                    break;
                                //设置蓝色
                                case OLED_LEVEL4_WS2812B_BLUE:
                                    if(oledSelectLevel2 == OLED_LEVEL2_WS2812B_CW_COLOR_INDEX)
                                    {
                                        uint16_t temp = oled_set_val(oledMenuWs2812bFixed.item[OLED_LEVEL4_WS2812B_BLUE].itemName,\
                                        ws2812bCwBlue, WS2812B_RGB_VAL_MIN, WS2812B_RGB_VAL_MAX);
                                        
                                        if(temp == 0xFFFF)
                                            break;
                                        
                                        ws2812bCwBlue = temp;
                                        ws2812bCwMode = 1;
                                    }
                                    else if(oledSelectLevel2 == OLED_LEVEL2_WS2812B_CCW_COLOR_INDEX)
                                    {
                                        uint16_t temp = oled_set_val(oledMenuWs2812bFixed.item[OLED_LEVEL4_WS2812B_BLUE].itemName,\
                                        ws2812bCcwBlue, WS2812B_RGB_VAL_MIN, WS2812B_RGB_VAL_MAX);
                                        
                                        if(temp == 0xFFFF)
                                            break;
                                        
                                        ws2812bCcwBlue = temp;
                                        ws2812bCcwMode = 1;
                                    }
                                    break;
                                default:
                                    break;
                            }
                        }
                        break;
                    default:
                        break;
                }
            }
            break;
        default:
            break;
    }
}
